import request from '@/config/axios'
import { defHttp } from '@/utils/http/axios';
import { RequestEnum } from '@/enums/httpEnum';
import { ServicePrefixEnum } from '@/enums/commonEnum';
import type { AxiosRequestConfig } from 'axios';

const MODULAR = '/system/role';

export const Api = {
  GetRolePage: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/page`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetSimpleRoleList: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/simple-list`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetRole: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/get`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  CreateRole: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/create`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  UpdateRole: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  UpdateRoleStatus: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update-status`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  deleteRole: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/delete`,
    method: RequestEnum.DELETE,
  } as AxiosRequestConfig,
}


// 查询角色列表
export const getRolePage = async (params) => {
  return defHttp.request({ ...Api.GetRolePage,params})
}

// 查询角色（精简)列表
export const getSimpleRoleList = async (): Promise<RoleVO[]> => {
  return await defHttp.request({ ...Api.GetSimpleRoleList})
}

// 查询角色详情
export const getRole = async (id: number) => {
  return await defHttp.request({ ...Api.GetRole,params:{id}})
}

// 新增角色
export const createRole = async (data: RoleVO) => {
  return await defHttp.request({ ...Api.CreateRole,params:data})
}

// 修改角色
export const updateRole = async (data: RoleVO) => {
  return await defHttp.request({ ...Api.UpdateRole,params:data})
}

// 修改角色状态
export const updateRoleStatus = async (data: UpdateStatusReqVO) => {
  return await defHttp.request({ ...Api.UpdateRoleStatus,params:data})
}

// 删除角色
export const deleteRole = async (id: number) => {
  return await defHttp.request({ ...Api.UpdateRoleStatus,params:{id}})
}

export interface RoleVO {
  id: number
  name: string
  code: string
  sort: number
  status: number
  type: number
  dataScope: number
  dataScopeDeptIds: number[]
  createTime: Date
}

export interface UpdateStatusReqVO {
  id: number
  status: number
}

// // 查询角色列表
// export const getRolePage = async (params: PageParam) => {
//   return await request.get({ url: '/system/role/page', params })
// }
//
// // 查询角色（精简)列表
// export const getSimpleRoleList = async (): Promise<RoleVO[]> => {
//   return await request.get({ url: '/system/role/simple-list' })
// }
//
// // 查询角色详情
// export const getRole = async (id: number) => {
//   return await request.get({ url: '/system/role/get?id=' + id })
// }
//
// // 新增角色
// export const createRole = async (data: RoleVO) => {
//   return await request.post({ url: '/system/role/create', data })
// }
//
// // 修改角色
// export const updateRole = async (data: RoleVO) => {
//   return await request.put({ url: '/system/role/update', data })
// }
//
// // 修改角色状态
// export const updateRoleStatus = async (data: UpdateStatusReqVO) => {
//   return await request.put({ url: '/system/role/update-status', data })
// }
//
// // 删除角色
// export const deleteRole = async (id: number) => {
//   return await request.delete({ url: '/system/role/delete?id=' + id })
// }

// 导出角色 todo
export const exportRole = (params) => {
  return request.download({
    url: '/system/role/export-excel',
    params
  })
}
